<script setup>
import { ref, onMounted } from "vue";
import { ElMessage, ElMessageBox } from 'element-plus'
import Layout from '@/layout/index.vue'

let status = ref(true)

onMounted(() => {
  loadData()
})

const loadData = async () => {
  const script_status = sessionStorage.getItem('script_status')
  if(script_status) return
  sessionStorage.setItem('script_status', 'true')
  const res = await requestData("https://api.hhxcaz.top/status").catch(_ => false)
  if(res) {
    status.value = false
  } else {
    ElMessageBox.alert('该版本为内测版本，功能可能存在为完善~后续会继续更新！请关注：https://gitee.com/hhxcaz', '脚本助手提示', {
    confirmButtonText: '好的',
  })
  }
}

// 请求数据
const requestData = (url, data = {}, method = "GET") => {
  return new Promise((resolve, reject) => {
    window
      .fetch(url, {
        method: method,
        headers: {
          "Content-Type": "application/json",
        },
        body: method == "GET" ? null : JSON.stringify(data),
      })
      .then((res) => resolve(res.json()))
      .catch((err) => reject(err, 'errr'));
  });
};
</script>

<template>
  <div class="main">
    <Layout v-if="status"></Layout>
  </div>
</template>

<style scoped>
</style>
